﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Jinjia.Approve.IService.JJFlow;
using Jinjia.Approve.IService.JJFlow.Action;
using Jinjia.Approve.Model.Input.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow.DTO;
using Jinjia.Approve.Model.VM.JJFlow.Request;
using Jinjia.Core.BaseInfrastructure.StorageModel.Model;

namespace Jinjia.Approve.Service.JJFlow
{
    public class JJFlowClientService : IJJFlowClientService
    {
        private readonly IJJFlowTemplateService _ijjFlowTemplateService;
        private readonly IJJFlowInstanceService _ijjFlowInstanceService;
        private readonly IJJFLowActionApprove _jjfLowActionApprove;

        public JJFlowClientService(IJJFlowTemplateService ijjFlowTemplateService,
            IJJFlowInstanceService ijjFlowInstanceService,
            IJJFLowActionApprove jjfLowActionApprove)
        {
            _ijjFlowTemplateService = ijjFlowTemplateService;
            _ijjFlowInstanceService = ijjFlowInstanceService;
            _jjfLowActionApprove = jjfLowActionApprove;
        }

        public async Task<int> GetTemplateID(string modular_key)
        {
            return await _ijjFlowTemplateService.GetTemplateID(modular_key);
        }

        public async Task<JjFlowInstanceVM> GetInstanceInfo(string modular_key, string biz_order_id)
        {
            return await _ijjFlowInstanceService.GetInstanceInfo(modular_key, biz_order_id);
        }

        public async Task<List<JjFlowInstanceVM>> GetInstanceListByIdsAsync(List<int> IdList)
        {
            return await _ijjFlowInstanceService.GetInstanceListAsync(o => o.deleted == 0 && o.status == "0" && IdList.Contains(o.id));
        }

        public async Task<NodeInfo> Approve(int flow_instance_id, int user_id, string remark, int is_auto_approve = 0)
        {
            var nodeInfo = await _jjfLowActionApprove.Approve(flow_instance_id, user_id, remark, is_auto_approve);
            return nodeInfo;
        }

        public async Task<List<string>> GetUserBizOrderId(QueryRequest request)
        {
            return await _ijjFlowInstanceService.GetUserBizOrderId(request.modular_key, request.user_id);
        }

        public async Task<PageListSearchResultVM<MyTodoListOverview>> GetMyTodoListOverview(int currentUserId, SearchConditionBaseInput input)
        {
            return await _ijjFlowInstanceService.GetMyTodoListOverview(currentUserId, input);
        }

        public async Task<int> GetMyTodoListCount(int currentUserId)
        {
            return await _ijjFlowInstanceService.GetMyTodoListCount(currentUserId);
        }


        public async Task<PageListSearchResultVM<MyTodoListDetail>> GetTodoListDetailForCurrentUser(int currentUserId, GetToDoListDetailByTab input)
        {
            return await _ijjFlowInstanceService.GetTodoListDetailForCurrentUser(currentUserId, input);
        }

        public async Task<IReadOnlyList<SearchByUrlResponse>> SearchByUrl(string url)
        {
            return await _ijjFlowInstanceService.SearchByUrl(url);
        }


    }
}